<?php
/**
 * File.php
 * uAPI Public License
 * @change: delete is keyword in C(++) method renamed to del
 * @author Bastie
 */
class uFile {

  private $path;

  function __construct ($path) {
    $this->path = $path;
  }

  function __destruct () {
    $this->path = NULL;
  }

  function exist () {
    return file_exists($this->path);
  }

  function isDirectory () {
    return is_dir($this->path);
  }

  function isFile () {
    return is_File ($this->path);
  }

  function makeDirectory () {
    return mkdir ($this->path,0777);
  }

  function del () {
    return unlink ($this->path);
  }

  function rename ($newName) {
    $ok = rename ($this->path, $newName);
    if (ok) {
      $this->path = $newName;
    }
    return $ok;
  }

  function listFiles () {
    $files = array ();
    if ($this->isDirectory ()) {
      $dir = openDir($this->path);
      while ($file = readDir($dir)) {
        if ($file != "." && $file != "..") {
          $newFileInstance = new uFile ($this->path . $file);
//print ($newFileInstance->__toString()."\n\r");
          array_push($files, $newFileInstance);
        }
      }
      closeDir($dir);
    }
    return $files;
  }

  function __toString () {
    return $this->path;
  }
}

?>